#include "SquareMapItem.h"
#include "MapCalculator.h"

SquareMapItem::SquareMapItem()
: PolygonMapItem(MapItemType::Square)
{

}

SquareMapItem::SquareMapItem(const QPointF& leftTop, double sideLength)
: PolygonMapItem(MapItemType::Square)
{
	Q_ASSERT(sideLength != 0);
	double insideAngle = atan(sideLength / sideLength);
	qreal azimuth = qRadiansToDegrees(insideAngle) + 90;

	double distance = sqrt(pow(sideLength, 2) + pow(sideLength, 2));
	QPointF rightBottom = MapCalculator::targetPoint(leftTop, azimuth, distance);

	QVector<QPointF> points;
	points.push_back(leftTop);
	points.push_back(QPointF(rightBottom.x(), leftTop.y()));
	points.push_back(rightBottom);
	points.push_back(QPointF(leftTop.x(), rightBottom.y()));
	setPoints(points);
}

SquareMapItem::~SquareMapItem()
{

}

